//
//  FDMMasterPersonalCollectionViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/22.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMMasterPersonalCollectionViewCell.h"
#import "FDMMasterModel.h"

@interface FDMMasterPersonalCollectionViewCell ()


@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) FDMBaseButton *attentionButton;

@end
@implementation FDMMasterPersonalCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.titleImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.titleImage];
        [self.titleImage release];
        self.titleLabel = [[FDMBaseLabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel release];
        self.attentionButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.attentionButton];
    }
    return self;
}

- (void)dealloc {
    [self.titleImage release];
    [self.titleLabel release];
    [self.attentionButton release];
    [super dealloc];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.contentView.layer.borderWidth = 5;
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(10);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.mas_bottom).with.offset(-10);
        make.right.equalTo(self.mas_right);
    }];
    self.titleImage.layer.borderColor = [UIColor whiteColor].CGColor;
    self.titleImage.layer.borderWidth = 3;
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.contentView.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-60);
        make.right.equalTo(self.contentView.mas_right);
    }];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleImage.mas_bottom).with.offset(10);
        make.left.equalTo(self.contentView.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-30);
        make.right.equalTo(self.contentView.mas_right);
        
    }];
    [self.attentionButton setTitle:@"+ 关注" forState:UIControlStateNormal];
    [self.attentionButton setTitleColor:[UIColor colorWithRed:1.00 green:0.36 blue:0.14 alpha:1.00] forState:UIControlStateNormal];
    [self.attentionButton addTarget:self action:@selector(attentionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.attentionButton.layer.cornerRadius = 5;
    self.attentionButton.layer.masksToBounds = YES;
    self.attentionButton.layer.borderWidth = 1;
    self.attentionButton.layer.borderColor = [UIColor colorWithRed:1.00 green:0.36 blue:0.14 alpha:1.00].CGColor;
    self.attentionButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.attentionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(-20);
        make.left.equalTo(self.contentView.mas_left).with.offset(30);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(- 30);
    }];
}

- (void)attentionButtonAction:(FDMBaseButton *)attentionButton {
    
}

- (void)setDetailModel:(FDMMasterModel *)detailModel {
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = [detailModel retain];
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_detailModel.smallLogo] placeholderImage:PLACEHOLDER_IMAGE];
        self.titleLabel.text = _detailModel.nickname;
//        [self.jumpDelegate clickCellToNextControllerWithImageStr:_detailModel.smallLogo];
        self.userId = [_detailModel.uid stringValue];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
